package com.itheima.service.db.imp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.mapper.BlackListMapper;
import com.itheima.service.db.BlackListService;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class BlackListServiceImp implements BlackListService {
    @Autowired
    private BlackListMapper blackListMapper;
    @Override//查询黑名单并分页
    public PageBeanVo findByPage(Long userId, Integer pageNum, Integer pageSize) {
        //创建mybatisPlus分页类填写条件
        Page page=new Page(pageNum,pageSize);
        //创建条件
        QueryWrapper qw=new QueryWrapper();
        //在黑名单列表中查询用户id列与实参userId相等的信息
        qw.eq("user_id",userId);
        //根据条件和分页条件查询出新page
        page = blackListMapper.selectPage(page, qw);
        //创建定义好的实体类 赋值 并返回
        return new PageBeanVo(pageNum,pageSize,page.getTotal(),page.getRecords());
    }

    @Override//移除黑名单
    public void remove(Long userId, Long blackUserId) {
        //创建条件
        QueryWrapper qw=new QueryWrapper();
        //删除信息需要满足userId和blackUserId同时相等
        qw.eq("user_id",userId);
        qw.eq("black_user_id",blackUserId);

        blackListMapper.delete(qw);
    }
}
